package nio.security;

import java.io.IOException;
import java.io.InputStream;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.util.Enumeration;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * KeyStoreHelper
 * 
 * @author nio
 */
public class KeyStoreHelper extends Object {
	private static final Logger log = LoggerFactory.getLogger(KeyStoreHelper.class);

	/**
	 * Create a new instance of the KeyStoreHelper.
	 */
	public KeyStoreHelper() {
		super();
	}

	public void list() {
		try {
			String type = "jks";
			KeyStore keyStore = KeyStore.getInstance(type);

			InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("alicekeystore.jks");
			char[] password = "alicestorepass".toCharArray();
			keyStore.load(stream, password);

			Enumeration<String> aliases = keyStore.aliases();
			for (; aliases.hasMoreElements();) {
				System.out.println(aliases.nextElement());
			}

		} catch (KeyStoreException e) {
			log.error(e.getMessage(), e);
		} catch (CertificateException e) {
			log.error(e.getMessage(), e);
		} catch (NoSuchAlgorithmException e) {
			log.error(e.getMessage(), e);
		} catch (IOException e) {
			log.error(e.getMessage(), e);
		}

	}

}
